<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        const cai = {
            uname: '鸡太美',
            age: 2.5,
            hobbit: ['sing', 'dance', 'rap', 'basketball'],
            fans: {
              uname: 'ikun',
              age: 9999,
              hobbit: ['smoke', 'drink', 'makeHairStyle'],
            },
        }

        // 准备一个空对象
        const fang = {}

        function deepClone(newObj, oldObj) {
            for(let key in oldObj) {
                if(oldObj[key] instanceof Array) {
                    newObj[key] = []

                    deepClone(newObj[key], oldObj[key])
                } else if (oldObj[key] instanceof Object) {
                    newObj[key] = {}

                    deepClone(newObj[key], oldObj[key])
                } else {
                    newObj[key] = oldObj[key]
                }
            }
        }
        deepClone(fang, cai)

        fang.fans.hobbit[2] = 'ikun喜欢鸡'
        console.log(cai);
        console.log(fang);
    </script>
</body>
</html>